package com.shouxin.attendance;

import android.app.Application;

import com.shouxin.attendance.activity.MainActivity;
import com.shouxin.attendance.serialport.SerialManager;
import com.shouxin.attendance.serialport.SoundHelper;
import com.shouxin.attendance.utils.TimeConfig;
import com.shouxin.attendance.utils.Utils;
import com.shouxin.log.log4j.LogUtils;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;

import org.apache.log4j.Logger;

public class App extends Application implements Thread.UncaughtExceptionHandler {

    private static App mInstance;

    private final Logger logger = Logger.getLogger(App.class);

    public static App getApp() {
        return mInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;

        LogUtils.init();
        Thread.setDefaultUncaughtExceptionHandler(this);

        Beta.canShowUpgradeActs.add(MainActivity.class);
        Beta.autoDownloadOnWifi = true;
        Beta.autoInit = true;
        Beta.autoCheckUpgrade = true;
        Beta.upgradeCheckPeriod = 600 * 1000;
        Beta.initDelay = 1000;

        Bugly.init(this, "a74e16c87e", BuildConfig.DEBUG);

        // 初始化声音文件
        SoundHelper.getInstance().initSounds();

        TimeConfig.get().initTime(this);

        Utils.initGlobalImageLoader();
        // 开始读取串口数据
        SerialManager.getInstance().onCreate();
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        logger.error("发生异常 =>", ex);
    }
}
